cmake_minimum_required ( VERSION 3.0 )
if (POLICY CMP0054)
  cmake_policy(SET CMP0054 NEW)
endif(POLICY CMP0054)
#set(CMAKE_CONFIGURATION_TYPES "Release;Debug")

project ( sqlite3 C )


## 从dist.info文件中读取信息
macro (read_file_content filename var)
	if ( NOT EXISTS ${filename} )
	  message ( FATAL_ERROR
		"文件 (${filename}) 不存在." )
	endif ()
	file ( READ ${filename} ${var} )

	if ( "${var}" STREQUAL "" )
	  message ( FATAL_ERROR "文件 ${filename} 没有内容." )
	endif ()
endmacro()

read_file_content(${CMAKE_CURRENT_SOURCE_DIR}/dist.info DIST_INFO)
message(STATUS ${DIST_INFO})

# Reads field `name` from dist.info string `DIST_INFO` into variable `var`.
macro ( _parse_dist_field name var )
  string ( REGEX REPLACE ".*${name}[ \t]?=[ \t]?[\"']([^\"']+)[\"'].*" "\\1"
           ${var} "${DIST_INFO}" )
  if ( ${var} STREQUAL DIST_INFO )
    message ( FATAL_ERROR "Failed to extract \"${var}\" from dist.info" )
  endif ()
endmacro ()
macro ( _parse_dist_field2 name var )
  string ( REGEX REPLACE ".*${name}[ \t]?=[ \t]?[\"']([^\"']+)[\"'].*" "\\1"
           ${var} "${DIST_INFO}" )
  if ( ${var} STREQUAL DIST_INFO )
    set ( ${var} "")
  endif ()
endmacro ()

#
_parse_dist_field ( name DIST_NAME )
_parse_dist_field ( version DIST_VERSION )
_parse_dist_field ( license DIST_LICENSE )
_parse_dist_field ( author DIST_AUTHOR )
_parse_dist_field ( maintainer DIST_MAINTAINER )
_parse_dist_field ( url DIST_URL )
_parse_dist_field ( desc DIST_DESC )
_parse_dist_field2 ( depends DIST_DEPENDS )

message ( "DIST_NAME: ${DIST_NAME}")
message ( "DIST_VERSION: ${DIST_VERSION}")
message ( "DIST_LICENSE: ${DIST_LICENSE}")
message ( "DIST_AUTHOR: ${DIST_AUTHOR}")
message ( "DIST_MAINTAINER: ${DIST_MAINTAINER}")
message ( "DIST_URL: ${DIST_URL}")
message ( "DIST_DESC: ${DIST_DESC}")
message ( "DIST_DEPENDS: ${DIST_DEPENDS}")